﻿<%@ WebHandler Language="C#" Class="DownloadNotics" %>

using System;
using System.Web;

public class DownloadNotics : IHttpHandler
{
    string filepath = Maticsoft.Common.ConfigHelper.GetConfigString("Noticfile");
    string filetype = Maticsoft.Common.ConfigHelper.GetConfigString("GetNoticType");
    public void ProcessRequest(HttpContext context)
    {
        GetNoticText(context);
    }

    /// <summary>
    /// 获取文件
    /// </summary>
    /// <param name="context"></param>
    public void GetNoticText(HttpContext context)
    {
        string mac = context.Request["mac"];//mac地址
        int id = BarberShop.BLL.DeviceInfoBLL.GetStoreIdByMac(mac);
        string filename = string.Format("gonggao_{0}.txt", id);
        long length=0;
        string _content = Maticsoft.Common.FileHelper.GetFileContent(filepath + filename,out length);
        BarberShop.BLL.DeviceInfoBLL.SetDeviceStatus(mac, 1);
        if (filetype == "1")
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write(_content);
        }
        else
        {
            context.Response.Clear();
            context.Response.Buffer = false;
            context.Response.ContentType = "application/octet-stream";
            context.Response.AppendHeader("content-disposition", "attachment;filename=gonggao.txt;");
            context.Response.AppendHeader("content-length",length.ToString());
            context.Response.Write(_content);
            context.Response.Flush();
            context.Response.End();
        }

    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
